package cn.hxzy.service.impl;

import cn.hxzy.domain.Course;
import cn.hxzy.domain.Direction;
import cn.hxzy.mapper.CourseMapper;
import cn.hxzy.mapper.DirectionMapper;
import cn.hxzy.service.DirectionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author niuyi
 * @since 2024-06-22
 */
@Service
public class DirectionServiceImpl extends ServiceImpl<DirectionMapper, Direction> implements DirectionService {
    @Autowired
    private DirectionMapper directionMapper;
    @Autowired
    private CourseMapper courseMapper;
    @Override
    public List<Direction> selectList() {
        return directionMapper.selectList(null);
    }

    @Override
    public List<Direction> selectBySchoolId(Integer schoolId) {
        return directionMapper.selectList(new QueryWrapper<Direction>()
                .eq("school_id",schoolId)
        );
    }

    @Override
    public List<Direction> selectDirectionByCourseId(Integer courseId) {

        Course course = courseMapper.selectById(courseId);
        course.getDirectionId().split(",");
        if (course.getDirectionId()!=null){
            return directionMapper.selectList(new QueryWrapper<Direction>()
                    .in("direction_id",course.getDirectionId().split(","))
            );
        }
        return null;
    }
}
